home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / mono.asm < prev    next >
Encoding:
Assembly Source File  |  2000-07-21  |  8.8 KB  |  494 lines

  1. ; Mono
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.2
  6.  
  7.     MACHINE    68020
  8.  
  9.         INCDIR    Include:
  10.  
  11.     INCLUDE exec/types.i
  12.     INCLUDE    exec/memory.i
  13.     INCLUDE    exec/exec_lib.i
  14.     INCLUDE    utility/tagitem.i
  15.     INCLUDE    intuition/intuition.i
  16.     INCLUDE    intuition/intuition_lib.i
  17.     INCLUDE    intuition/screens.i
  18.     INCLUDE    graphics/graphics_lib.i
  19.     INCLUDE graphics/modeid.i
  20.     INCLUDE    graphics/rastport.i
  21.     INCLUDE    dos/dos.i
  22.     INCLUDE    dos/dos_lib.i
  23.     INCLUDE    libraries/asl.i
  24.     INCLUDE    libraries/asl_lib.i
  25.     INCLUDE    macros.i
  26.  
  27. ;*** Handler structure
  28.  
  29.  STRUCTURE vxd_handler,0
  30.   LONG intuibase
  31.   LONG graphbase
  32.   LONG dosbase
  33.   LONG aslbase
  34.   LONG myscr
  35.   LONG mywin
  36.   LONG planes
  37.   WORD xsize
  38.   WORD ysize
  39.   LONG palette
  40.   LONG palettemono
  41.   LONG emuscr
  42.   LONG cmpbuffer
  43.   LONG scrmodereq
  44.   LONG screendim
  45.   WORD bytesperrow
  46.   WORD skip
  47.  LABEL    vxd_handler_SIZEOF
  48.  
  49. JSRLIB    MACRO
  50.     jsr    _LVO\1(a6)
  51.     ENDM
  52.  
  53. ;*** Let's begin
  54.  
  55.     moveq.l    #0,d0
  56.     rts
  57.  
  58.     dc.b "FLAMINGOXVD"
  59.     dc.b "2"
  60.  
  61.     dc.l Name
  62.     dc.l Author
  63.     dc.w 1
  64.     dc.w 2
  65.  
  66.     dc.l drv_Init
  67.     dc.l drv_Done
  68.     dc.l drv_Configure
  69.     dc.l drv_OpenScreen
  70.     dc.l drv_CloseScreen
  71.     dc.l drv_Refresh
  72.     dc.l 0            ;No PPC refresh
  73.  
  74. Name:    dc.b    "Mono (B&W) External Video Driver",0
  75. Author:    dc.b    "Álmos Rajnai",0
  76.  
  77.     EVEN
  78.  
  79. ;*** Functions
  80.  
  81. drv_Init:
  82.     movem.l    a0-a1,-(sp)    ;Saving infos
  83.     move.l  4.w,a6        ;Alloc memory for handler
  84.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  85.     move.l    #vxd_handler_SIZEOF,d0
  86.     JSRLIB    AllocVec
  87.     movem.l    (sp)+,a0-a1    ;Recover infos
  88.         cmp.l    #0,d0
  89.     beq.b    .1        ;No mem
  90.     movea.l    d0,a2
  91.         move.l    (a0),graphbase(a2)    ;Saving graphics.library base
  92.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  93.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  94.         move.l    16(a0),aslbase(a2)    ;Saving asl.library base
  95.         movem.l    d0,-(sp)
  96.  
  97.     move.l    dosbase(a2),a6        ;Reading config file
  98.     move.l    #configfile,d1        ;Config file is pretty simple:
  99.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  100.     JSRLIB    Open
  101.     tst.l    d0
  102.     beq.b    .2            ;Failed open
  103.     move.l    d0,d1
  104.     move.l    (sp),a0
  105.     lea    screendim(a0),a0
  106.     move.l    a0,d2
  107.     moveq.l    #4,d3
  108.     movem.l    d0,-(sp)
  109.     JSRLIB    Read            ;Reading the 4 bytes
  110.     cmp.l    #4,d0
  111.     beq.b    .3
  112.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  113.     move.l    #0,screendim(a0)
  114.  
  115. .3    movem.l    (sp)+,d1
  116.     JSRLIB    Close
  117.  
  118. .2    movem.l    (sp)+,d0
  119. .1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  120.     rts                ;Result in D0 available for now
  121.  
  122. drv_Done:
  123.     movea.l    a0,a1
  124.     cmpa.l    #0,a1
  125.     beq.b    .1
  126.     movem.l    4.w,a6
  127.     JSRLIB    FreeVec        ;Deallocate handler
  128. .1
  129.     rts
  130.  
  131. drv_Configure:            ;Configure
  132.                 ;A simple screenmode requester appears
  133.     movem.l    a0,-(sp)
  134.     move.l    screendim(a0),displayid
  135.     move.l    #ASL_ScreenModeRequest,d0    
  136.     move.l    aslbase(a0),a6
  137.     lea    asltags,a0
  138.     JSRLIB    AllocAslRequest
  139.     move.l    (sp),a0
  140.     move.l    d0,scrmodereq(a0)
  141.     tst.l    d0
  142.     bne.b    config2
  143.     move.l    intuibase(a0),a6
  144.     JSRLIB    DisplayBeep
  145.     lea    4(sp),sp
  146.     rts
  147.  
  148. config2:
  149.     move.l    d0,a0
  150.     suba.l    a1,a1
  151.     JSRLIB    AslRequest
  152.     tst.l    d0
  153.     beq.b    .1
  154.  
  155.     move.l    (sp),a1
  156.     move.l    scrmodereq(a1),a0
  157.     move.l    sm_DisplayID(a0),screendim(a1)
  158.  
  159.     move.l    dosbase(a1),a6        ;Writing config file
  160.     move.l    #configfile,d1        ;Config file is pretty simple:
  161.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  162.     JSRLIB    Open
  163.     tst.l    d0
  164.     beq.b    .1            ;Failed open
  165.     move.l    d0,d1
  166.     move.l    (sp),a0
  167.     lea    screendim(a0),a0
  168.     move.l    a0,d2
  169.     moveq.l    #4,d3
  170.     movem.l    d0,-(sp)
  171.     JSRLIB    Write            ;Writing the 4 bytes
  172.  
  173.     movem.l    (sp)+,d1        ;We don't care too much on
  174.     JSRLIB    Close            ;success...
  175.  
  176. .1    movem.l    (sp)+,a0
  177.     move.l    aslbase(a0),a6
  178.     move.l    scrmodereq(a0),a0
  179.     JSRLIB    FreeAslRequest
  180.     rts
  181.  
  182. drv_OpenScreen:
  183.     movea.l a0,a5
  184.     move.w    (a1)+,xsize(a5)
  185.     move.w    (a1)+,ysize(a5)
  186.     move.l    (a1)+,palette(a5)
  187.     move.l    screendim(a5),screenmode    ;screenmode from init
  188.  
  189.     moveq.l    #0,d0
  190.     move.l    d0,d1
  191.     move.w    xsize(a5),d0
  192.     move.w    ysize(a5),d1
  193.     mulu.w    d1,d0
  194.     move.l    d0,d7    
  195.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  196.     move.l    4.w,a6
  197.     JSRLIB    AllocVec
  198.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  199.     beq.w    .1
  200.  
  201.     move.l    d7,d0
  202.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  203.     JSRLIB    AllocVec
  204.     move.l    d0,cmpbuffer(a5)    ;allocating cmp buffer
  205.     beq.w    .1
  206.  
  207.     move.l    #MEMF_PUBLIC,d1
  208.     move.l    #8*128,d0
  209.     JSRLIB    AllocVec
  210.     move.l    d0,palettemono(a5)    ;Convert palette to 1 bit
  211.     beq.w    .1
  212.     movea.l    d0,a0
  213.     move.l    #128-1,d2
  214.         move.l    palette(a5),a1
  215.     moveq.w    #0,d0
  216. .2    moveq.w    #0,d1
  217.     move.b    (a1)+,d1        ;Sum of R,G,B
  218.     move.b    (a1)+,d0
  219.     add.w    d0,d1
  220.     move.b    (a1)+,d0
  221.     add.w    d0,d1
  222.     cmp.w    #255,d1            ;Less than a third?
  223.     blt.b    .less
  224.     move.b    #$ff,d3
  225.     bra.b    .cont
  226. .less    move.b    #$0,d3
  227. .cont    move.b    d3,d4
  228.     and.b    #1<<0,d4
  229.     move.b    d4,128*7(a0)
  230.     move.b    d3,d4
  231.     and.b    #1<<1,d4
  232.     move.b    d4,128*6(a0)
  233.     move.b    d3,d4
  234.     and.b    #1<<2,d4
  235.     move.b    d4,128*5(a0)
  236.     move.b    d3,d4
  237.     and.b    #1<<3,d4
  238.     move.b    d4,128*4(a0)
  239.     move.b    d3,d4
  240.     and.b    #1<<4,d4
  241.     move.b    d4,128*3(a0)
  242.     move.b    d3,d4
  243.     and.b    #1<<5,d4
  244.     move.b    d4,128*2(a0)
  245.     move.b    d3,d4
  246.     and.b    #1<<6,d4
  247.     move.b    d4,128*1(a0)
  248.     move.b    d3,d4
  249.     and.b    #1<<7,d4
  250.     move.b    d4,(a0)+
  251.     dbf    d2,.2
  252.     move.w    xsize(a5),width+2
  253.     move.w    ysize(a5),height+2
  254.  
  255.         suba.l    a0,a0            ;No newscreen stuct
  256.         lea    scrtags,a1
  257.     movea.l    intuibase(a5),a6
  258.     JSRLIB    OpenScreenTagList
  259.     move.l    d0,myscr(a5)
  260.     beq.w    .1
  261.     move.l    d0,wscr
  262.     move.l    d0,a0
  263.     lea    sc_RastPort(a0),a0
  264.     movea.l    rp_BitMap(a0),a0
  265.     move.l    #BMA_FLAGS,d1
  266.     movea.l    graphbase(a5),a6
  267.     JSRLIB    GetBitMapAttr
  268.     and.l    #BMF_STANDARD,d0
  269.     cmp.l    #BMF_STANDARD,d0
  270.     beq.b    .3
  271.     movea.l    intuibase(a5),a6
  272.     move.l    myscr(a5),a0
  273.     JSRLIB    CloseScreen
  274.     moveq.l    #0,d0
  275.     move.l    d0,myscr(a5)
  276.     bra.b    .1
  277.  
  278. .3    move.w    xsize(a5),wwidth+2
  279.     move.w    ysize(a5),wheight+2
  280.     suba.l    a0,a0
  281.     lea    wintags,a1
  282.     movea.l    intuibase(a5),a6
  283.     JSRLIB    OpenWindowTagList
  284.     move.l    d0,mywin(a5)
  285.     beq.b    .1
  286.     movea.l    d0,a1
  287.     move.l  wd_RPort(a1),a0
  288.     move.l    rp_BitMap(a0),a0
  289.     move.l    bm_Planes(a0),planes(a5)
  290.     move.w    xsize(a5),d0
  291.     lsr.w    #3,d0
  292.     move.w    d0,d1
  293.     move.w    d1,bytesperrow(a5)
  294.     move.w    bm_BytesPerRow(a0),d1
  295.     sub.w    d0,d1
  296.     move.w    d1,skip(a5)
  297.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  298.     move.l    emuscr(a5),d2        ;chunky buffer
  299.  
  300. .1    move.l    #err_noscr,d1
  301.     moveq.l    #0,d3            ;No modulo for the chunky screen
  302.     rts
  303.  
  304. drv_CloseScreen:
  305.     move.l    a0,a5
  306.     move.l    intuibase(a5),a6
  307.     move.l    mywin(a5),a0
  308.     cmpa.l    #0,a0
  309.     beq.b    .1
  310.     JSRLIB    CloseWindow
  311.  
  312. .1    move.l    myscr(a5),a0
  313.     cmpa.l    #0,a0
  314.     beq.b    .2
  315.     JSRLIB    CloseScreen
  316.  
  317. .2    movea.l    palettemono(a5),a1
  318.         cmpa.l    #0,a1
  319.     beq.b    .3
  320.     move.l    4.w,a6
  321.     JSRLIB    FreeVec        ;Deallocate translated palette
  322.  
  323. .3    movea.l    emuscr(a5),a1
  324.         cmpa.l    #0,a1
  325.     beq.b    .4
  326.     move.l    4.w,a6
  327.     JSRLIB    FreeVec        ;Deallocate chunky buffer
  328. .4
  329.     movea.l    cmpbuffer(a5),a1
  330.         cmpa.l    #0,a1
  331.     beq.b    .5
  332.     move.l    4.w,a6
  333.     JSRLIB    FreeVec        ;Deallocate delta buffer
  334. .5
  335.     moveq.l    #0,d0
  336.     move.l    d0,emuscr(a5)    ;They were already freed
  337.     move.l    d0,cmpbuffer(a5)
  338.     move.l    d0,palettemono(a5)
  339.     move.l    d0,myscr(a5)
  340.     move.l    d0,mywin(a5)
  341.  
  342.     rts
  343.  
  344. drv_Refresh:
  345.  
  346.     move.w    ysize(a0),d0
  347.     subq.w    #1,d0
  348.     movea.l    emuscr(a0),a1
  349.     movem.l    a1,-(sp)        ;storing chunky buffer
  350.     movea.l    palettemono(a0),a4
  351.     movea.l    planes(a0),a3
  352.     moveq.l    #0,d3
  353.     move.l    d3,d5
  354.     move.l    d3,d7
  355.     move.l    d3,d4
  356.     move.w    skip(a0),d7
  357.     move.w    bytesperrow(a0),d5
  358.     move.w    xsize(a0),d4
  359.     movea.l    cmpbuffer(a0),a0
  360.  
  361. .difcyc2
  362.     move.w    d4,d6
  363.     lsr.w    #2,d6
  364.     subq.w    #1,d6
  365.     movea.l    a1,a6
  366.     movea.l    a0,a5
  367. .difcyc    cmp.l    (a6)+,(a5)+
  368.     beq.b    .nodifference
  369.  
  370.     move.w    d5,d6    
  371.     subq.l    #1,d6
  372. .cyc    moveq.b    #0,d2
  373.     movea.l    a4,a2
  374.  
  375.     move.b    (a1)+,d3
  376.     move.b    d3,(a0)+
  377.     or.b    (a2,d3.w),d2
  378.     adda.l    #128,a2
  379.  
  380.     move.b    (a1)+,d3
  381.     move.b    d3,(a0)+
  382.     or.b    (a2,d3.w),d2
  383.     adda.l    #128,a2
  384.  
  385.     move.b    (a1)+,d3
  386.     move.b    d3,(a0)+
  387.     or.b    (a2,d3.w),d2
  388.     adda.l    #128,a2
  389.  
  390.     move.b    (a1)+,d3
  391.     move.b    d3,(a0)+
  392.     or.b    (a2,d3.w),d2
  393.     adda.l    #128,a2
  394.  
  395.     move.b    (a1)+,d3
  396.     move.b    d3,(a0)+
  397.     or.b    (a2,d3.w),d2
  398.     adda.l    #128,a2
  399.  
  400.     move.b    (a1)+,d3
  401.     move.b    d3,(a0)+
  402.     or.b    (a2,d3.w),d2
  403.     adda.l    #128,a2
  404.  
  405.     move.b    (a1)+,d3
  406.     move.b    d3,(a0)+
  407.     or.b    (a2,d3.w),d2
  408.     adda.l    #128,a2
  409.  
  410.     move.b    (a1)+,d3
  411.     move.b    d3,(a0)+
  412.     or.b    (a2,d3.w),d2
  413.  
  414.     move.b    d2,(a3)+
  415.     dbf    d6,.cyc
  416.     bra.b    .cont
  417.  
  418. .nodifference
  419.     dbf    d6,.difcyc
  420.     adda.l    d5,a3
  421.     adda.l    d4,a1
  422.     adda.l    d4,a0
  423. .cont    adda.l    d7,a3
  424.     dbf    d0,.difcyc2
  425.  
  426.     movem.l    (sp)+,d0    ;giving back chunky buffer
  427.     
  428.         rts
  429.  
  430. ;*** Constants
  431.  
  432. scrtags:
  433.     dc.l    SA_Width
  434. width:    dc.l    0
  435.     dc.l    SA_Height
  436. height:    dc.l    0
  437.     dc.l    SA_Depth,1
  438.     dc.l    SA_Colors32,mypalette
  439.     dc.l    SA_Title,scrtitle
  440.     dc.l    SA_ShowTitle,FALSE
  441.     dc.l    SA_DisplayID
  442. screenmode:
  443.     dc.l    0
  444.     dc.l    SA_Interleaved,TRUE
  445.     dc.l    SA_Type,CUSTOMSCREEN
  446.     dc.l    SA_AutoScroll,TRUE
  447.     dc.l    SA_Overscan,OSCAN_STANDARD
  448.     dc.l    SA_Quiet,TRUE
  449.     dc.l    TAG_DONE
  450.  
  451. wintags:
  452.     dc.l    WA_Left,0
  453.     dc.l    WA_Top,0
  454.     dc.l    WA_Width
  455. wwidth:    dc.l    0
  456.     dc.l    WA_Height
  457. wheight:    dc.l    0
  458.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  459.     dc.l    WA_Title,0
  460.     dc.l    WA_Backdrop,TRUE
  461.     dc.l    WA_RMBTrap,TRUE
  462.     dc.l    WA_Borderless,TRUE
  463.     dc.l    WA_NoCareRefresh,TRUE
  464.     dc.l    WA_CustomScreen
  465. wscr:    dc.l    0
  466.     dc.l    WA_SimpleRefresh,TRUE
  467.     dc.l    WA_Activate,TRUE
  468.     dc.l    TAG_DONE
  469.  
  470. mypalette:
  471.     dc.w    2,0
  472.     dc.l    0,0,0,$ff000000,$ff000000,$ff000000,0,0,0,0
  473.  
  474. asltags:
  475.     dc.l    ASLSM_TitleText,configwintxt
  476.     dc.l    ASLSM_InitialDisplayID
  477. displayid:
  478.     dc.l    0
  479.     dc.l    TAG_DONE
  480.  
  481.  
  482. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  483.  
  484. configwintxt:    dc.b    'Choose desired screenmode',0
  485.  
  486. configfile:    dc.b    'mono.cfg',0
  487.  
  488. ;*** Errors
  489.  
  490. err_nomem:
  491.     dc.b    'Ran out of memory',0
  492. err_noscr:
  493.     dc.b    'Cannot open screen',0
  494.